
import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button } from 'antd';
import styles from './Users.css';
import moment from 'moment';
import Factory from '../factory';
import * as datetime from '../../utils/datetime'
import dataEditCreate from '../addons/DataEdit'
import dataTableCreate from '../addons/DataTable'
import * as menuService from '../../services/menus'
import * as com from '../../utils/common';
import YJRDS from './YJRDS'
const daoName = "QDTYZC";
const ButtonGroup = Button.Group;
const columns = [
  { title: '客户名称', width: 300, sorter: true, dataIndex: 'Khmc', key: 'Khmc', dispaly: true, filter: true },
  { title: '开户网点', width: 170, sorter: true, dataIndex: 'Khwd', key: 'Khwd', dispaly: true, filter: true },
  { title: '科目', width: 200, sorter: true, dataIndex: 'Kaimu', key: 'Kaimu', dispaly: true, filter: true },
  { title: '币种', width: 100, sorter: true, dataIndex: 'Huobi', key: 'Huobi', dispaly: true, filter: true },
  { title: '帐号', width: 190, sorter: true, dataIndex: 'Zhao', key: 'Zhao', dispaly: true, filter: true },
  { title: '开户日均', className: 'column-money', render: data => com.formatNumber(data.Dqye), key: 'Dqye', width: 180, sorter: true, dispaly: true, filter: true },
  { title: '上日余额', className: 'column-money', render: data => com.formatNumber(data.Yqje), key: 'Yqje', width: 180, sorter: true, dispaly: true, filter: true },
  { title: '当前余额', className: 'column-money', render: data => com.formatNumber(data.Ddangqye), key: 'Ddangqye', width: 180, sorter: true, dispaly: true, filter: true },
  { title: '中间业务收入', className: 'column-money', render: data => com.formatNumber(data.Zjywsr), key: 'Zjywsr', width: 180, sorter: true, dispaly: true, filter: true },
  { title: '是否协议存款', width: 170, sorter: true, dataIndex: 'Xyck', key: 'Xyck', dispaly: true, filter: true },
  { title: '是否定期质押存款', width: 170, sorter: true, dataIndex: 'Dqyck', key: 'Dqyck', dispaly: true, filter: true },
  { title: '备注', width: 100, sorter: true, dataIndex: 'Bzhu', key: 'Bzhu', dispaly: true, filter: true },
  { title: '帐户性质', width: 170, sorter: true, dataIndex: 'Zhxz', key: 'Zhxz', dispaly: true, filter: true },
  { title: '结息方式', width: 170, sorter: true, dataIndex: 'Jxfs', key: 'Jxfs', dispaly: true, filter: true },
  { title: '存期', width: 100, sorter: true, dataIndex: 'Cqi', key: 'Cqi', dispaly: true, filter: true },
  { title: '月日均', className: 'column-money', render: data => com.formatNumber(data.Ffje), key: 'Ffje', width: 180, sorter: true, dispaly: true, filter: true },
  { title: '帐户调整系数2', dataIndex: 'Zhtzxs', key: 'Zhtzxs', width: 180, sorter: true, dispaly: true, filter: true },
  { title: '帐户调整系数', dataIndex: 'Zhte', key: 'Zhte', width: 180, sorter: true, dispaly: true, filter: true },
  { title: '利率', dataIndex: 'Ll', key: 'Ll', width: 180, sorter: true, dispaly: true, filter: true },
  { title: 'FTP', dataIndex: 'Ftp', key: 'Ftp', width: 180, sorter: true, dispaly: true, filter: true },
  { title: '存期ID', dataIndex: 'Cqid', key: 'Cqid', width: 180, sorter: true, dispaly: true, filter: true },
  { title: '统计类型', dataIndex: 'Tjlx', key: 'Tjlx', width: 180, sorter: true, dispaly: true, filter: true },
  { title: '开户日期', width: 110, sorter: true, key: 'Khrq', caption: "Khrq", render: data => datetime.format(data.Khrq, "yyyy-MM-dd"), dispaly: true, filter: true, canEdit: true },
  { title: '销户日', width: 110, sorter: true, key: 'Xhr', caption: "Xhr", render: data => datetime.format(data.Xhr, "yyyy-MM-dd"), dispaly: true, filter: true, canEdit: true },
  { title: '起息日', width: 110, sorter: true, key: 'Qxr', caption: "Qxr", render: data => datetime.format(data.Qxr, "yyyy-MM-dd"), dispaly: true, filter: true, canEdit: true },
  { title: '到期日', width: 110, sorter: true, key: 'Dqr', caption: "Dqr", render: data => datetime.format(data.Dqr, "yyyy-MM-dd"), dispaly: true, filter: true, canEdit: true },
];
const controls = [
  { name: 'Xyck', required: true, type: 'text', label: '是否协议存款', grid: 12 / 24 },
  { name: 'Dqyck', required: true, type: 'text', label: '是否定期质押存款', grid: 12 / 24 },
  { name: 'Bzhu', required: true, type: 'text', label: '备注', grid: 12 / 24 },
  { name: 'Zhxz', required: true, type: 'text', label: '帐户性质', grid: 12 / 24 },
  { name: 'Jxfs', required: true, type: 'text', label: '结息方式', grid: 12 / 24 },
  { name: 'Cqi', required: true, type: 'text', label: '存期', grid: 12 / 24 },
  { name: 'Khmc', required: true, type: 'text', label: '客户名称', grid: 12 / 24 },
  { name: 'Kaimu', required: true, type: 'text', label: '科目', grid: 12 / 24 },
  { name: 'Huobi', required: true, type: 'text', label: '币种', grid: 12 / 24 },
  { name: 'Khwd', required: true, type: 'text', label: '开户网点', grid: 12 / 24 },
  { name: 'Zhao', required: true, type: 'text', label: '帐号', grid: 12 / 24 },
  { name: 'Ffje', required: true, type: 'alphanum', label: '月日均', grid: 12 / 24 },
  { name: 'Dqye', required: true, type: 'alphanum', label: '开户日均', grid: 12 / 24 },
  { name: 'Yqje', required: true, type: 'alphanum', label: '上日余额', grid: 12 / 24 },
  { name: 'Ddangqye', required: true, type: 'alphanum', label: '当前余额', grid: 12 / 24 },
  { name: 'Zjywsr', required: true, type: 'alphanum', label: '中间业务收入', grid: 12 / 24 },
  { name: 'Zhtzxs', required: true, type: 'alphanum', label: '帐户调整系数2', grid: 12 / 24 },
  { name: 'Zhte', required: true, type: 'alphanum', label: '帐户调整系数', grid: 12 / 24 },
  { name: 'Ll', required: true, type: 'alphanum', label: '利率', grid: 12 / 24 },
  { name: 'Ftp', required: true, type: 'alphanum', label: 'FTP', grid: 12 / 24 },
  { name: 'Cqid', required: true, type: 'alphanum', label: '存期ID', grid: 12 / 24 },
  { name: 'Tjlx', required: true, type: 'alphanum', label: '统计类型', grid: 12 / 24 },
  { name: 'Khrq', required: true, type: 'date', label: '开户日期', grid: 12 / 24, dataType: "date" },
  { name: 'Xhr', required: true, type: 'text', label: '销户日', min: 2, max: 30, grid: 12 / 24 },
  { name: 'Qxr', required: true, type: 'text', label: '起息日', min: 2, max: 30, grid: 12 / 24 },
  { name: 'Dqr', required: true, type: 'text', label: '到期日', min: 2, max: 30, grid: 12 / 24 },
]
const DataTable = dataTableCreate(daoName);
class QDTYZCS extends Component {
  constructor(props) {
    super(props);
    this.state = {
      dataChange: false
    };
  }
  componentDidMount() {
    this.props.dispatch({
      type: `${daoName}/setKeyName`,
      payload: { keyName: "ID" }
    });
    this.props.dispatch({
      type: `${daoName}/fetch`,
      payload: { daoName, page: 1, pageSize: 20 }
    });
    this.loadOptionData();
  }
  loadOptionData() {
    let options = []
    controls.map(c => {
      if (c.fetch) {
        let f = c.fetch;
        if (c.type === 'cascader-select') {
          f.isCascader = true;
        }
        if (c.type !== 'search') {
          options.push(f);
        }
      }
    })
    if (daoName && options.length > 0) {
      this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
    }
  }
  showModelHandler(isAdd) {
    let key = null
    if (!isAdd) {
      const len = this.props.selectedRowKeys.length;
      if (len === 0) {
        message.info('请选择要编辑的行，如果选择了多行，则使用最后一次选择！');
        return;
      }
      key = this.props.selectedRowKeys[len - 1]
    }
    this.props.dispatch({
      type: `${daoName}/openEdit`,
      payload: { key }
    });
  }
  hideEditHandler() {
    if (this.state.dataChange) {
      this.props.dispatch({
        type: `${daoName}/reload`,
        payload: { daoName },
      });
      this.state.dataChange = false;
    }
    this.props.dispatch({
      type: `${daoName}/hideEdit`
    });
  };
  render() {
    let { showEdit, record } = this.props
    return (
      <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
        <div>
          <div className={styles.create}>
            <ButtonGroup style={{ zIndex: 0 }}>
              <Button onClick={this.showModelHandler.bind(this, false)}>业绩认定</Button>
            </ButtonGroup>
          </div>
          <Modal title={record.Khmc + "业绩分配"} width={700} visible={showEdit} onCancel={this.hideEditHandler.bind(this)}>
            <YJRDS ywid={record.ID} />
          </Modal>
          <DataTable ref="userTable" daoName={daoName} columns={columns} controls={controls} />
        </div>
      </div>
    )
  }
}
function mapStateToProps(state) {
  const { showEdit, record, selectedRowKeys, keyName } = state[daoName];
  return {
    showEdit,
    selectedRowKeys,
    keyName,
    record
  }
}
QDTYZCS = connect(mapStateToProps)(QDTYZCS)
export default QDTYZCS;
let render = (props) => React.createElement(QDTYZCS, props);

let f = new Factory()
f.set("QDTYZCS", render)
